package com.danco.planner.viewcontrollers;

import com.danco.planner.services.SpeakersListService;
import com.danco.planner.supportclasses.enumeration.IEventType;
import com.danco.planner.supportclasses.enumeration.PlannerEventType;
import com.danco.planner.view.builders.AbstractViewsBuilder;
import com.danco.planner.view.builders.ConsoleViewsBuilder;
import com.danco.planner.view.core.AbstractButton;
import com.danco.planner.view.core.View;

public class SpeakersVC extends AbstractPlannerVC {

	public SpeakersVC() {
		super();
		// TODO Auto-generated constructor stub
	}
	public SpeakersVC(View view) {
		super(view);
		// TODO Auto-generated constructor stub
	}
	public SpeakersVC(View view, String title) {
		super(view, title);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	protected void initAllOtherSubviews() {
		
		AbstractViewsBuilder builder = new ConsoleViewsBuilder();
		
		AbstractButton sortByNameBtn = builder.buildButton("Sort by name", "sbName", PlannerEventType.sortByName);
		AbstractButton sortByCoursesCount = builder.buildButton("Sort by courses count", "sbCrCount", PlannerEventType.sortByCoursesCount);
		
		sortByNameBtn.addListener(this);
		sortByCoursesCount.addListener(this);
		
		baseView.addSubviews(sortByNameBtn,sortByCoursesCount);
	}
	@Override
	protected String getMainContent() {
		return SpeakersListService.getSpeakersListDescription();
	}
	
	@Override
	public void handleAction(Object arg0, IEventType arg1) {
		
		super.handleAction(arg0, arg1);
		
		if (arg1 == PlannerEventType.sortByName) {
			sortByName();
		}
		else if (arg1 == PlannerEventType.sortByCoursesCount) {
			sortByCoursesCount();
		}	
	}
	
	private void sortByName() {
		this.contentLabel.setText(SpeakersListService.getSpeakersListDescriptionSortedByName());
	}
	private void sortByCoursesCount() {
		this.contentLabel.setText(SpeakersListService.getSpeakersListDescriptionSortedByCoursesCount());
	}
}
